package admin.action;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;

import home.model.PageBean;
import home.model.Skill;
import home.service.SkillService;

import com.opensymphony.xwork2.ActionSupport;

public class SkillMngAction extends ActionSupport{
	private SkillService skills;
	private List<Skill> skillList;
	private Skill skillEdit;
	private int id;
	public List<Skill> getSkillList() {
		return skillList;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setSkillList(List<Skill> skillList) {
		this.skillList = skillList;
	}

	public Skill getSkillEdit() {
		return skillEdit;
	}

	public void setSkillEdit(Skill skillEdit) {
		this.skillEdit = skillEdit;
	}

	public SkillService getSkills() {
		return skills;
	}

	public void setSkills(SkillService skills) {
		this.skills = skills;
	}
	private int page;
	private PageBean pageBean;
	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public PageBean getPageBean() {
		return pageBean;
	}

	public void setPageBean(PageBean pageBean) {
		this.pageBean = pageBean;
	}
	private String like;
	public String getLike() {
		return like;
	}

	public void setLike(String like) {
		this.like = like;
	}

	public String execute() throws Exception{
		pageBean = skills.queryForPage(8, page, like);
		skillList = pageBean.getList();
		System.out.println(skillList);
		return SUCCESS;
	}
	public String add(){
		return SUCCESS;
	}
	public String addSubmit(){
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date=new Date(System.currentTimeMillis());
		skillEdit.setCreated_at(df.format(date));
		skillEdit.setCreated_by("MsgMngAction/addSubmit");
		skillEdit.setUpdated_at(df.format(date));
		skillEdit.setUpdated_by("MsgMngAction/addSubmit");

		skills.saveSkill(skillEdit);
		return SUCCESS;
	}
	public String edit(){
		skillEdit = skills.getSkill(id);
		if(skillEdit == null) return INPUT;
		return SUCCESS;
	}
	public String editSubmit(){
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date=new Date(System.currentTimeMillis());
		skillEdit.setUpdated_at(df.format(date));
		skillEdit.setUpdated_by("MsgMngAction/editSubmit");

		skills.saveSkill(skillEdit);
		return SUCCESS;
	}
	public String delete(){
		skills.deleteSkillById(id);
		return SUCCESS;
	}
}
